﻿@using System.Collections.Specialized
@
@model List<KPIS.GERP.SERVICE.Model.approval_task>

@{
    ViewBag.Title = "จัดการงานอนุมัติที่กำลังดำเนินการอยู่ในระบบ";
}

<h2>@ViewBag.Title</h2>
    <table id="box-table-a" style="width:90%">
        <thead>
            <tr>
                <th scope="col">รหัส</th> 
                <th scope="col">หัวข้อคำขอ</th> 
                <th scope="col">ผู้ขอ</th> 
                <th scope="col">สร้างเมื่อ</th> 
                <th scope="col">จบเมื่อ</th> 

                <th scope="col">สถานะ</th> 
                <th scope="col">ขั้นตอนที่</th> 
                <th scope="col">กฎอนุมัติ</th> 
                <th scope="col">สิ้นสุด</th> 
                <th scope="col">ผู้อนุมัติ</th>

                <th scope="col">เชื่อมโยง</th> 
                <th scope="col">รายละเอียด</th> 
                
            </tr>
        </thead>
        <tbody>
            @if(Model != null && Model.Count  > 0)
            {
                foreach(var m in Model)
                { 
                    <tr>
                        <td>
                            @m.ApprovalTaskSeq 
                            <img src="~/Images/Icons/Notice-Info-icon.png" width="16" height="16" title="@m.WfInstantId"/>
                        </td> 
                        <td>@m.Title</td>
                        <td>@(m.RequestEmp == null ? "-" : m.RequestEmp.full_name)</td>
                        <td>@m.StartWhen.ToShortDateString()</td>
                        <td>@(m.StopWhen == null ? "-" : m.StopWhen.Value.ToShortDateString())</td>

                        <td>@m.StatusWord </td>
                        <td>@(m.CurrentRuleApprove == null ? "-" : (m.CurrentRuleApprove.step.HasValue ? "" + m.CurrentRuleApprove.step : "-") + " จาก " + m.RuleApproves.Count)</td>
                        <td>@(m.CurrentRuleApprove == null ? "-" : m.CurrentRuleApprove.rule_approve_type.rule_approve_type_name)</td>
                        <td>@(m.Completed ? "สิ้นสุดแล้ว" : "อยู่ระหว่างพิจารณา")</td>
                        <td>
                            @if (m.CurrentRuleApprove != null)
                            {
                                int i = 1;
                                @m.ApproverEmployees.Aggregate("", (current, em) => current + Html.Raw("" + (i++) + ". " + em.full_name ))
                            } else
                            {
                                @("-")
                            }
                        </td>
                        <td>
                            
                            @{
                                var ruleApproveCustomButtons = m.CurrentRuleApprove == null ||
                                                               (m.CurrentRuleApprove != null && m.custom_buttons == null) 
                                                                   ? new List<rule_approve_custom_button>()
                                                                   : m.custom_buttons;
                            }
                            @if (ruleApproveCustomButtons != null)
                            {
                                foreach(var cb in ruleApproveCustomButtons)
                                {
                                    <a href="JavaScript:newPopup('@cb.navigate_url');" title="@cb.rule_approve_custom_name">
                                        @cb.rule_approve_custom_name 
                                        <img src="~/Images/Icons/external_website_icon1.png" width="12" height="12"/>
                                    </a>
                                    @Html.Raw("&nbsp;")
                                }
                            }
                            else
                            {
                                @Html.Raw("-")
                            }
                        </td>
                        <td>
                            @Html.ActionLink("ดูข้อมูล", "ViewDetails", new {approvalTaskSeq = m.ApprovalTaskSeq})
                        </td>
                    </tr> 
                }
            }
            else
            {
                <tr>
                    <td colspan="12">ไม่มีข้อมูล..</td>
                </tr>
            }
        </tbody>
    </table> 

<style type="text/css">
    .content {
        padding: 5px 10px;
        background-color:#fafafa; 
    }
    .heading {
        margin: 1px;
        color: #0366a5;
        padding: 3px 10px;
        cursor: pointer;
        position: relative;
        background-color:#d4e7ea;
    }
</style>

@section scripts{ 
    <script type="text/javascript">
        
        jQuery(document).ready(function () {
            jQuery(".content").hide();
            jQuery(".heading").click(function () {
                jQuery(this).next(".content").slideToggle(500);
            });
        });
        
        // Popup window code
        function newPopup(url) {
            var popupWindow = window.open(
                url,'popUpWindow','height=550,width=900,left=0,top=0,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
        }

    </script>
}